$(function () {
    init(true);
    $("input").keyup(function () {
        if ($.trim($("input[name='account']").val()) != "" && $.trim($("input[name='password']").val()) != "") {
            $("#login").css({"cursor": "pointer"});
        } else {
            $("#login").css({"cursor": "not-allowed"});
        }
    });

    $("#login").click(function () {
        if ($.trim($("input[name='account']").val()) == "" || $.trim($("input[name='password']").val()) == "") {
            return;
        }
        //TODO ajax提交服务端
        console.info("请求服务端登录....")
    });
});

$(window).resize(function () {
    init(false);
});

var bgImgWidth = 1920;
var bgImgHeight = 1080;

function init(initBg) {
    if (initBg) {
        var imageIndex = Math.floor(Math.random() * 10 + 1) + ".jpg";
        $("body").css({"background-image": "url(/images/bg" + imageIndex + ")"});
    }

    var windowHeight = $(window).height();
    var windowWidth = $(window).width();
    var left = (windowWidth - bgImgWidth) / 2;
    var top = (windowHeight - bgImgHeight) / 2;
    $("body").css({"backgroundPosition": left + "px " + top + "px"});
    var loginPaneWidth = $("#login-panel").outerWidth();
    var loginPaneHeight = $("#login-panel").outerHeight();
    var paneLeft = (windowWidth - loginPaneWidth) / 2;
    var paneTop = (windowHeight - loginPaneHeight) / 2;
    $("#login-panel").css({"left": paneLeft + "px", "top": paneTop + "px"});
    $("#login-panel").show();
}